
		<h1>Set Sub-Aff URL</h1>
		
		<form id="subaff" action="" method="post" autocomplete="off" data-confirm-send="false">
		<table class="greentable">
			<tr>
				<td>Name&nbsp;</td>
				<td><input style="width:275px;" type="text" id="name" name="name" value="">&nbsp;</td>
			</tr>
			<tr>
				<td>Url&nbsp;</td>
				<td><input style="width:275px;" type="text" id="url" name="url" value="">&nbsp;</td>
			</tr>
			<tr>
				<td>IB only&nbsp;</td>
				<td>
					<input type="radio" id="ib_only-yes" name="ib_only" value="yes"> Yes 
					<input type="radio" id="ib_only-no" name="ib_only" value="no" checked> No</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>
					<input type="submit" id="btSave" name="btSave" value="Save">&nbsp;
				</td>
			</tr>
		</table>
		</form>
		
		<table class="greentable">
			<thead>
				<tr>
					<th>#</th>
					<th>Name</th>
					<th>Url</th>
					<th>&nbsp;</th>
				</tr>
				</thead>
				<tbody>
				<?php
						$links = new Ref_link();
						$links->order_by('id', 'asc')->get();
						foreach($links as $link)
						{
				?>
				 <tr>
					<td><?php echo $link->id; ?></td>
					<td><?php echo $link->name; ?></td>
					<td><?php echo $link->url; ?></td>
					<td class="actions" style="width:25em;">
						<a class="del" title="Delete" href="javascript:void(0);" onclick="deleteLink('<?=$link->id?>');">delete</a>
					</td>
				</tr>
				<?
						}
				?>
				</tbody>
		</table>
		
		<div id="dialog"></div>
		
		<script language="javascript">	
				try {
					var jxworking  = false;
					jQuery(document).ready(function(){
							jQuery('#subaff').submit(function(){
									if(jxworking) 
									{
											jQuery('#btSave').after('<span id="wait-flash" style="color:#ff0000;">&nbsp;&nbsp;Please wait...</span>');
											setTimeout('$("#wait-flash").remove();', 3000);
											sendEmailStart = true;
									}
									else
									{
											saveSubAffUrl();
									}
									return false;
							});
					});
				} catch(err) {
					alert(err.message);
				}
				
				function deleteLink(link_id) {
						if(!confirm('Are you sure that you want to delete this Url?')) return false;
						
						jQuery.blockUI({ message: '<h3><img src="'+__base_url+'images/busy.gif" /> Deleting...</h3>' });
						jQuery.ajax({
								type: 'POST',
								url: __base_url+'admin/jx_delete_ref_link',
								data: 'link_id='+link_id,
								cache:false,
								success: function(msg){
										jQuery.unblockUI();
										// alert(msg);
										location.reload();
								},
								error: function(xhr,ajaxOptions,thrownError){
										jQuery.unblockUI();
										alert(xhr.responseText);
								}
						});
				}
				
				function saveSubAffUrl() {
						try {
								resetErrors();
								if(!jQuery('#name').val())
								{
										propError('name', 'Required');
										return false;
								}
								if(jQuery('#name').val().length<3)
								{
										propError('name', '3 characters min.');
										return false;
								}
								if(jQuery('#name').val().length>100)
								{
										propError('name', '100 characters max.');
										return false;
								}
								if(!jQuery('#url').val())
								{
										propError('url', 'Required');
										return false;
								}
								if(jQuery('#url').val().length>255)
								{
										propError('url', '255 characters max.');
										return false;
								}
								var patt = /^(https?:\/\/)?(www[0-9]{0,3}\.)?[a-zA-Z0-9\.-]+[a-zA-Z]{2,4}[\/a-zA-Z0-9;:\?\.%_=&\|@~-]*$/i;
								var _u = jQuery('#url').val();
								if(!patt.test(_u))
								{
										propError('url', 'Invalid URL');
										return false;
								}
								
								jQuery.blockUI({ message: '<h3><img src="'+__base_url+'images/busy.gif" /> Saving...</h3>' });
								var postdata = jQuery('#subaff').serialize();
								jQuery.ajax({
										type: 'POST',
										url: __base_url+'admin/jx_ref_link',
										data: postdata,
										cache:false,
										success: function(msg){
												jQuery.unblockUI();
												// alert(msg);
												try {
														var _obj = jQuery.parseJSON(msg);
														if(typeof _obj.error!='undefined' && typeof _obj.field_id!='undefined')
														{
																propError(_obj.field_id, _obj.error);
														}
														else if(typeof _obj.success!='undefined')
														{
																location.reload();
														}
												} catch(err){ alert(err.message); }
										},
										error: function(xhr,ajaxOptions,thrownError){
												jQuery.unblockUI();
												alert(xhr.responseText);
										}
								});
						} catch(err) {
							alert(err.message);
						}
				}
				
				function propError(field_id, error) {
						jQuery('#'+field_id).after('<span class="error" style="color:#ff0000;font-weight:bold;">&nbsp;&nbsp;'+error+'</span>');
				}
				
				function resetErrors() {
						jQuery('form span.error').remove();
				}
				
		</script>